package com.ibuonline.search.solr.extend;

import java.util.List;

public class DocumentHandlerManager {
	private static final String DEFAULT_PREFIX = "live_";
	private String prefix = DEFAULT_PREFIX;

	private List<DocumentHander> handlers;

	public void add(SolrIndexContext context) {
		context.handleDocumentWithPrefix(prefix);
		if (handlers != null && !handlers.isEmpty()) {
			for (DocumentHander handler : handlers) {
				handler.add(context);
			}
		}
	}

	public boolean delete(Object id) {
		if (handlers != null && !handlers.isEmpty()) {
			for (DocumentHander handler : handlers) {
				if (!handler.delete(id)) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * @param handlers
	 *            the handlers to set
	 */
	public void setHandlers(List<DocumentHander> handlers) {
		this.handlers = handlers;
	}

	/**
	 * @param prefix
	 *            the prefix to set
	 */
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
}
